/**
 * 
 */
package com.shine.cotrun.exp;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zsy
 *
 */
public class ExportConf {
	private String expToDir;//导出到文件夹
	private String expFileName;//导出文件名
	private List<ExportField> fields;//导出列名（表头）
	public ExportConf(String expToDir, String expFileName, 
			List<ExportField> fields) {
		this.expToDir = expToDir;
		this.expFileName = expFileName;
		this.fields = fields;
		
	}
	
	public ExportConf() {
		
	}

	public String getExpToDir() {
		return expToDir;
	}
	public void setExpToDir(String expToDir) {
		this.expToDir = expToDir;
	}
	public String getExpFileName() {
		return expFileName;
	}
	public void setExpFileName(String expFileName) {
		this.expFileName = expFileName;
	}
	public List<ExportField> getFields() {
		return fields;
	}
	public void setFields(List<ExportField> fields) {
		this.fields = fields;
	}
	
	/**
	 * 添加列配置
	 * @param expColumnName
	 * @param expPropertie
	 * @param type
	 */
	public void addField(String expColumnName, String expPropertie, Class<?> type, int length) {
		if (fields == null) {
			fields = new ArrayList<ExportField>();
		}
		fields.add(new ExportField(expColumnName, expPropertie, type, length));
	}
	
	/**
	 * 添加列配置
	 * @param expColumnName
	 * @param expPropertie
	 * @param type
	 */
	public void addField(String expColumnName, String expPropertie, Class<?> type) {
		addField(expColumnName, expPropertie, type, 0);
	}
	
	/**
	 * 添加列配置
	 * @param expColumnName
	 * @param expPropertie
	 */
	public void addField(String expColumnName, String expPropertie) {
		addField(expColumnName, expPropertie, null, 0);
	}
	
	/**
	 * 取得第i个列配置
	 * @param i
	 * @return
	 */
	public ExportField getField(int i) {
		return fields.get(i);
	}

	/**
	 * 列数
	 * @return
	 */
	public int getColumnSize() {
		if (fields == null) {
			return 0;
		}
		return fields.size();
	}

	/**
	 * 字段转方法名
	 * @param fieldName
	 * @return
	 */
	public String toMethod(String fieldName) {
		if (fieldName == null || fieldName.length() == 0) {
			return fieldName;
		}
	    StringBuffer sb = new StringBuffer(fieldName);
	    sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
	    return "get" + sb.toString();  
	}
	
	
	public class ExportField {
		private String expColumnName;//导出列名（表头）
		private String expPropertie;//导出属性（bean get开头的方法有效）
		private Class<?> type;//字段类型
		private int length;//字段长度
		public ExportField(String expColumnName, String expPropertie) {
			this(expColumnName, expPropertie, null, 0);
		}
		public ExportField(String expColumnName, String expPropertie, Class<?> type) {
			this(expColumnName, expPropertie, type, 0);
		}
		
		public ExportField(String expColumnName, String expPropertie, Class<?> type, int length) {
			this.expColumnName = expColumnName;
			this.expPropertie = expPropertie;
			this.type = type;
			this.length = length;
		}
		public String getExpColumnName() {
			return expColumnName;
		}
		public void setExpColumnName(String expColumnName) {
			this.expColumnName = expColumnName;
		}
		public String getExpPropertie() {
			return expPropertie;
		}
		public void setExpPropertie(String expPropertie) {
			this.expPropertie = expPropertie;
		}
		public Class<?> getType() {
			return type;
		}
		public void setType(Class<?> type) {
			this.type = type;
		}
		public int getLength() {
			return length;
		}
		public void setLength(int length) {
			this.length = length;
		}
		
	}
}
